package top.kaoshanji.p2ch09a;

/**
 * 代码清单-p2ch09a-293页a：当前类加载器对象优先的类加载器
 * author kaoshanji
 * ^_^
 * create time 2025/1/28 16:50
 */
public class ParentLastClassLoader extends ClassLoader {

    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {

        Class<?> clazz = findLoadedClass(name);
        if (null != clazz) {
            return clazz;
        }
        clazz = findClass(name);
        if (null != clazz) {
            return clazz;
        }
        ClassLoader parent = getParent();
        if (null != parent) {
            return parent.loadClass(name);
        } else {
            return super.loadClass(name, resolve);
        }
    }
}
